<?php


namespace app\lunwen\controller;


use app\lunwen\model\StuTopicLogModel;
use app\lunwen\model\StuTopicModel;
use cmf\controller\HomeBaseController;

//院系操作
class DepartmentOperateController extends HomeBaseController
{
    //审批课题
    public function examineTitle(){
        $department_title = new StuTopicModel();
        $data = $department_title->whereor("status","导师通过")
            ->whereor("status","院系通过")
            ->whereor("status","院系不通过")
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))

            ->all();
        $this->assign('title',$data);
        return $this->fetch(':departmentExamineTitle');
    }


    //根据状态 选中全部
    public function all(){
        //返回 列表
        //直接查询 学生选题 表
        //把对应的状态 改成文字
        $department_title = new StuTopicModel();
        $data = $department_title->whereor("status","导师通过")
            ->whereor("status","院系通过")
            ->whereor("status","院系不通过")
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))

            ->all();
        $this->assign('title',$data);
        return $this->fetch(':departmentExamineTitle');
    }

    //未审批的 课题
    public function noExamine(){
        //查询学生选题表 状态为2的
        $department_title = new StuTopicModel();
        $data = $department_title->where('status','导师通过')
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))

            ->all();
        $this->assign('title',$data);
        return $this->fetch(':departmentExamineTitle');
    }

    //已审批
    public function alreadyExamine(){
        //查询学生选题表  状态为 4.5的
        $department_title = new StuTopicModel();
        $data = $department_title->whereor('status','院系通过')
            ->whereor('status','院系不通过')
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))

            ->all();
        $this->assign('title',$data);
        return $this->fetch(':departmentExamineTitle');
    }

    //通过
    public function pass(){
        //获取当前元素的 父父元素 拿到里面的值 放到数组中去
        //判断 当前的状态 是否是1、7 是就通过 改变状态为2 加入日志表
        //echo $_GET['stu_name'];
        //echo $_GET['stu_id'];
        //查出当前这一条的数据
        $title = new StuTopicModel();
        $data = $title->where('stu_id',$_GET['stu_id'])->find();
        //var_dump ($data);
        if($data->status=="导师通过"){
            //改状态
            $department_jg = new StuTopicModel();
            $department_jg->save(
                ['status'=>'院系通过'],
                ['stu_id'=>$_GET['stu_id']]
            );

            //保存日志

            //echo $data->stu_title;
            $department_jg_log = new StuTopicLogModel();
            $department_jg_log->stu_name=$_GET['stu_name'];
            $department_jg_log->title=$data->stu_title;
            $department_jg_log->status='院系通过';
            $department_jg_log->stu_id=$_GET['stu_id'];

            $department_jg_log->save();

            $department_title = new StuTopicModel();
            $data = $department_title->whereor("status","导师通过")
                ->whereor("status","院系通过")
                ->whereor("status","院系不通过")
                ->whereTime('create_time','>',session('beforeYear'))
                ->whereTime('create_time','<',session('afterYear'))
                ->all();
            $this->assign('title',$data);
            return $this->fetch(':departmentExamineTitle');
        }
        else{
            //不是1或者7的状态不修改
            $this->assign('msg',"当前状态不能审批");
            //返回 列表
            //直接查询 学生选题 表
            //把对应的状态 改成文字
            $department_title = new StuTopicModel();
            $data = $department_title->whereor("status","导师通过")
                ->whereor("status","院系通过")
                ->whereor("status","院系不通过")
                ->whereTime('create_time','>',session('beforeYear'))
                ->whereTime('create_time','<',session('afterYear'))
                ->all();
            $this->assign('title',$data);
            return $this->fetch(':departmentExamineTitle');
        }
    }

    //不通过
    public function notpass(){
        //获取当前元素的 父父元素 拿到里面的值 放到数组中去
        //判断 当前的状态 是否是1、7 是就不通过 改变状态为3 加入日志表
        //echo $_GET['stu_name'];
        //echo $_GET['stu_id'];
        //查出当前这一条的数据
        $title = new StuTopicModel();
        $data = $title->where('stu_id',$_GET['stu_id'])->find();
        //var_dump ($data);

        if($data->status=="导师通过"){
            //改状态
            $teacher_jg = new StuTopicModel();
            $teacher_jg->save(
                ['status'=>'院系不通过'],
                ['stu_id'=>$_GET['stu_id']]
            );

            //保存日志

            //echo $data->stu_title;
            $department_jg_log = new StuTopicLogModel();
            $department_jg_log->stu_name=$_GET['stu_name'];
            $department_jg_log->title=$data->stu_title;
            $department_jg_log->status='院系不通过';
            $department_jg_log->stu_id=$_GET['stu_id'];
            $department_jg_log->save();

            $department_title = new StuTopicModel();
            $data = $department_title->whereor("status","导师通过")
                ->whereor("status","院系通过")
                ->whereor("status","院系不通过")
                ->whereTime('create_time','>',session('beforeYear'))
                ->whereTime('create_time','<',session('afterYear'))
                ->all();
            $this->assign('title',$data);
            return $this->fetch(':departmentExamineTitle');
        }
        else{
            //不是1或者7的状态不修改
            $this->assign('msg',"当前状态不能审批");
            //返回 列表
            //直接查询 学生选题 表
            //把对应的状态 改成文字
            $department_title = new StuTopicModel();
            $data = $department_title->whereor("status","导师通过")
                ->whereor("status","院系通过")
                ->whereor("status","院系不通过")
                ->whereTime('create_time','>',session('beforeYear'))
                ->whereTime('create_time','<',session('afterYear'))
                ->all();
            $this->assign('title',$data);
            return $this->fetch(':departmentExamineTitle');
        }
    }
}